Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mdast-util-find-and-replace

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-find-and-replace

mdast utility to find and replace text in a tree

  • 2.2.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is mdast-util-find-and-replace?

The mdast-util-find-and-replace npm package is a utility for finding and replacing text or patterns in Markdown Abstract Syntax Trees (MDAST). It is particularly useful for manipulating Markdown documents programmatically, allowing developers to automate content updates, apply transformations, and enhance Markdown processing workflows.

What are mdast-util-find-and-replace's main functionalities?

Text Replacement

This feature allows you to replace specific text in the MDAST. In the provided code, 'world' is replaced with 'universe' within the text node of a paragraph.

const u = require('unist-builder');
const findAndReplace = require('mdast-util-find-and-replace');

const tree = u('paragraph', [
  u('text', 'Hello world!')
]);

findAndReplace(tree, {'world': 'universe'});

console.log(tree);

Pattern Replacement with Callback

This feature allows replacing patterns using regular expressions. In the example, occurrences of 'example.com' are turned into clickable links.

const u = require('unist-builder');
const findAndReplace = require('mdast-util-find-and-replace');

const tree = u('paragraph', [
  u('text', 'Visit example.com for more info.')
]);

findAndReplace(tree, /example\.com/g, (match) => {
  return {
    type: 'link',
    url: 'http://example.com',
    children: [{type: 'text', value: match}]
  };
});

console.log(tree);

Other packages similar to mdast-util-find-and-replace

Keywords

FAQs

Package last updated on 26 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc